CXX = g++
CXXFLAGS = -std=c++17 -Wall -g
INCLUDES = -Iinclude -I/usr/include/opencv4 $(shell pkg-config --cflags libavcodec libavformat libswscale libavutil)
LDFLAGS = $(shell pkg-config --libs libavcodec libavformat libswscale libavutil) -lopencv_core -lopencv_highgui -pthread

SRCS = $(wildcard src/*.cpp)
OBJS = $(patsubst src/%.cpp, build/%.o, $(SRCS))
DIRS = $(sort $(dir $(OBJS)))

TARGET = FFmpegDemo

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CXX) -o $@ $^ $(LDFLAGS)

build/%.o: src/%.cpp | $(DIRS)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

$(DIRS):
	mkdir -p $@

clean:
	rm -rf build $(TARGET)

.PHONY: all clean
